Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Pubsub.SeenMessagesTTL #9372

Merged
merged 6 commits into from
Nov 28, 2022
Merged

Conversation

smrz2001
Copy link
Contributor

@smrz2001 smrz2001 commented Oct 26, 2022

Here's a PR for this issue, @lidel.

cc @stbrody

Closes #9371

go.mod Show resolved Hide resolved
@lidel lidel self-assigned this Oct 26, 2022
@lidel lidel self-requested a review October 26, 2022 20:58
@smrz2001 smrz2001 force-pushed the feat/seen-messages-ttl-config branch from 5a9aa6c to c74d8c0 Compare November 4, 2022 15:56
@lidel lidel force-pushed the feat/seen-messages-ttl-config branch from c74d8c0 to 27a4bd1 Compare November 9, 2022 19:36
@lidel lidel changed the title feat: make pubsub seen messages cache ttl configurable feat: Pubsub.SeenMessagesTTL Nov 9, 2022
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, but this needs tests – if we expose this setting, we must be sure it continues working across any future refactors (both Kubo and go-libp2p)

@@ -77,6 +77,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
pubsubOptions = append(
pubsubOptions,
pubsub.WithMessageSigning(!cfg.Pubsub.DisableSigning),
pubsub.WithSeenMessagesTTL(cfg.Pubsub.SeenMessagesTTL.WithDefault(pubsub.TimeCacheDuration)),
Copy link
Member

@lidel lidel Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR needs a basic regression test that ensures Pubsub.SeenMessagesTTL set by the user is respected.
Unsure what is the best way to test this, you'd need to set it too low and then observe duplicates?

@smrz2001 we have some prior art in test/sharness/t0320-pubsub.sh if that helps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @lidel, it took me a bit to get everything figured out and setup with sharness. After playing around with it a bit, I'm realizing that there isn't really a good way to induce duplicate pubsub messages. The API (rightly) doesn't allow setting a message ID explicitly.

func (t *Topic) Publish(ctx context.Context, data []byte, opts ...PubOpt) error {
.
.
.
	return t.p.val.PushLocal(&Message{m, "", t.p.host.ID(), nil, pub.local})
}

The only option I can currently come up with is to use tc netem via command line or code to simulate network traffic duplication.

Does this seems like a viable approach? Not sure what the restrictions are around what tests are/aren't allowed to do. I've used tc netem before so I can figure this out, if acceptable.

Copy link
Member

@lidel lidel Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for looking into this. I hoped there is an easier way, but I guess we've hit an edge case on this one.

We already have some helpers for sharness in ./test/dependencies, such as pollEndpoint, so that is a potential path forward (golang helper is a bit more future-proof, could be reused when we move away from the sharness). Using tc netem is also an option, if we can get it to work on CI.

@marten-seemann @vyzo is there a better / less painful way to test WithSeenMessagesTTL / simulate duplicated messages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking aloud here but I could also make a libp2p-sim tool under test/dependencies that connects to libp2p like a normal node but is capable of sending spurious messages. Might be useful in other contexts too perhaps.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not, we do go out of our way to supress them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about having a libp2p-sim that implements it's own Publish and can send dups?

This and libp2p/go-libp2p-pubsub#502 both sound sensible 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lidel, would it be possible to do a regular Golang unit test here instead of adding to sharness?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lidel, after a lot of hair pulling, I was unable to set up a libp2p simulator but I was able to figure out how to write a Go test under test/integration that does the job, IMO. Would it work to keep the test there? Let me know what you think.

FYI, this test uncovered another pubsub/cache bug, which I will fix under this issue.

Copy link
Member

@lidel lidel Nov 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for doing due diligence on this, yes, your approach is acceptable: this is the best we can do given tools at hand, and it still acts as an early warning if go-libp2p APIs change, or a regression is introduced.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for driving this @smrz2001, and being patient with test work. I'm merging this, so we can include it in Kubo 0.18.0-rc1 (ETA second week of December, or beginning of January).

Excellent, thanks so much, @lidel!! 🙏🏼🙏🏼

I'll try to get the other bugs fixed soon as well, and will update the dependencies and tests accordingly.

docs/config.md Show resolved Hide resolved
config/pubsub.go Outdated Show resolved Hide resolved
@smrz2001 smrz2001 force-pushed the feat/seen-messages-ttl-config branch from 3c73341 to 4b8eafa Compare November 28, 2022 20:19
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for driving this @smrz2001, and being patient with test work.
I'm merging this, so we can include it in Kubo 0.18.0-rc1 (ETA second week of December, or beginning of January).

test/integration/pubsub_msg_seen_cache_test.go Outdated Show resolved Hide resolved
test/integration/pubsub_msg_seen_cache_test.go Outdated Show resolved Hide resolved
@@ -77,6 +77,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
pubsubOptions = append(
pubsubOptions,
pubsub.WithMessageSigning(!cfg.Pubsub.DisableSigning),
pubsub.WithSeenMessagesTTL(cfg.Pubsub.SeenMessagesTTL.WithDefault(pubsub.TimeCacheDuration)),
Copy link
Member

@lidel lidel Nov 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for doing due diligence on this, yes, your approach is acceptable: this is the best we can do given tools at hand, and it still acts as an early warning if go-libp2p APIs change, or a regression is introduced.

@lidel lidel enabled auto-merge (squash) November 28, 2022 22:03
@lidel lidel merged commit 51f60ea into ipfs:master Nov 28, 2022
@smrz2001 smrz2001 deleted the feat/seen-messages-ttl-config branch November 28, 2022 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add optional Pubsub.SeenMessagesTTL to Kubo config
3 participants